package com.superbytecode.cloud.common.model.mq;

import com.superbytecode.cloud.common.utils.DateUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.Duration;
import java.time.LocalDateTime;

/**
 * All rights Reserved, Designed By www.super-master.com
 *
 * @ProjectName: beacon-cloud
 * @Package: com.superbytecode.cloud.common.message
 * @ClassName: MQConfigure
 * @Description: [MQ消息配置]
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2024/11/1 15:36
 * @Version: V1.0
 * @Copyright: 2024 www.super-master.com Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class MQConfigure {
    /**
     * topic标签
     */
    private String tag;
    /**
     * 哈希值
     * <p>设置了同一hash值的消息可保证消费顺序</p>
     */
    private String hash;
    /**
     * 延迟级别（支持开源rocketmq）
     */
    private DelayedLevel delayedLevel;
    /**
     * 消息交付时间（延时消息的发送时间，阿里云rocketmq）
     */
    private Long deliverTime;

    //
    public void setDelayTime(Duration delayDuration) {
        this.deliverTime = System.currentTimeMillis() + delayDuration.toMillis();
    }

    public void setDelayTime(LocalDateTime startDeliverTime) {
        this.deliverTime = DateUtil.toMillis(startDeliverTime);
    }
}